/*     */ package nc.pubimpl.ic.atp.service;
/*     */ 
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import nc.bs.framework.common.NCLocator;
/*     */ import nc.bs.ic.atp.pub.ATPBill;
/*     */ import nc.bs.ic.atp.pub.ATPBillManage;
/*     */ import nc.bs.ic.atp.pub.ATPSessionCtrl;
/*     */ import nc.bs.ic.pub.env.ICBSContext;
/*     */ import nc.impl.pubapp.env.BSContext;
/*     */ import nc.pubitf.ic.atp.ATPUpdate;
/*     */ import nc.pubitf.ic.atp.IATPService;
/*     */ import nc.vo.ic.atp.entity.AtpVO;
/*     */ import nc.vo.ic.atp.pub.AtpVOUtil;
/*     */ import nc.vo.ic.pub.pf.billtype.BillTypeInfoQuery;
/*     */ import nc.vo.ic.pub.util.CollectionUtils;
/*     */ import nc.vo.ic.pub.util.VOEntityUtil;
/*     */ import nc.vo.ic.pub.util.ValueCheckUtil;
/*     */ import nc.vo.pub.AggregatedValueObject;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pub.CircularlyAccessibleValueObject;
/*     */ import nc.vo.pub.lang.UFDouble;
/*     */ import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/*     */ import nc.vo.scmpub.util.SagasUtil;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ATPUpdateImpl
/*     */   implements ATPUpdate
/*     */ {
/*     */   public void abandonATPCheck() {
/*  54 */     if (!SagasUtil.isNccnativeMerged()) {
/*  55 */       BSContext.getInstance().setSession("ATPCheck", "false");
/*     */     } else {
/*  57 */       ((IATPService)NCLocator.getInstance().lookup(IATPService.class)).abandonATPCheck();
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void modifyATPAfter(String cbilltype, AggregatedValueObject[] billparams) throws BusinessException {
/*     */     try {
/*  68 */       ATPSessionCtrl ctl = new ATPSessionCtrl();
/*  69 */       AggregatedValueObject[] bills = ctl.combineBillVOs(cbilltype, billparams);
/*  70 */       ctl.remoteAtpBillIDs(cbilltype, bills);
/*  71 */       if (!ctl.checkIsGoing(cbilltype, bills, 0)) {
/*     */         return;
/*     */       }
/*     */       
/*  75 */       AtpVO[] beforeAtpVOs = ctl.getAtpVOs(cbilltype, bills);
/*  76 */       ctl.clearAtpVOs(cbilltype, bills);
/*     */       
/*  78 */       AtpVO[] aftervos = ATPBillManage.getInstance().getAllATPVOs(cbilltype, bills, false);
/*  79 */       Object map = (new ICBSContext()).getSession("bodyid_atpdim_key");
/*  80 */       if (map != null) {
/*  81 */         aftervos = processAtpVos(billparams, aftervos, (Map)map, cbilltype);
/*     */       }
/*     */       
AtpVO[] updatevos =
VOEntityUtil.mergeDiffNumVOs(CollectionUtils.combineArrs(
    AtpVO.atpDims, new String[] {
      AtpVO.PK_BATCHCODE
    }), AtpVO.atpNums, aftervos, beforeAtpVOs);/*     */ 
/*     */ 
/*     */       
/*  88 */       updatevos = AtpVOUtil.filterZeroAtpVO(updatevos);
/*  89 */       if (ValueCheckUtil.isNullORZeroLength(updatevos)) {
/*     */         return;
/*     */       }
/*  92 */       IATPService service = (IATPService)NCLocator.getInstance().lookup(IATPService.class);
/*  93 */       if (!SagasUtil.isNccnativeMerged() && !ATPBillManage.getInstance().isCurrMoudle(cbilltype)) {
/*  94 */         service.checkAtp(updatevos);
/*     */       }
/*  96 */       service.updateAtp(updatevos);
/*     */     }
/*  98 */     catch (Exception ex) {
/*  99 */       ExceptionUtils.marsh(ex);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public AtpVO[] modifyATPBefore(String cbilltype, AggregatedValueObject[] bills) throws BusinessException {
/*     */     try {
/* 110 */       ATPSessionCtrl ctl = new ATPSessionCtrl();
/* 111 */       ctl.addAtpBillIDs(cbilltype, bills);
/* 112 */       if (!ctl.checkIsGoing(cbilltype, bills, 1)) {
/* 113 */         return null;
/*     */       }
/* 115 */       ctl.putBillVOs(cbilltype, bills);
/* 116 */       AtpVO[] vos = ATPBillManage.getInstance().getAllATPVOs(cbilltype, bills, true);
/* 117 */       ctl.putAtpVOs(cbilltype, bills, vos);
/* 118 */       return vos;
/*     */     }
/* 120 */     catch (Exception ex) {
/* 121 */       ExceptionUtils.marsh(ex);
/*     */       
/* 123 */       return null;
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/* 128 */   public void abandonATPCheckByOrgs(Set<String> pk_orgs) { ((IATPService)NCLocator.getInstance().lookup(IATPService.class)).abandonATPCheckByOrgs(pk_orgs); }
/*     */ 
/*     */ 
/*     */   
/*     */   private AtpVO[] processAtpVos(AggregatedValueObject[] billparams, AtpVO[] atpvos, Map<String, Object> bidAndDimmap, String cbilltype) throws BusinessException {
/* 133 */     AtpVO[] sourceAtpvo = (AtpVO[])(new ICBSContext()).getSession("source_before_atpvo");
/* 134 */     BillTypeInfoQuery infoQuery = (new ICBSContext()).getBillTypeInfo();
/* 135 */     if (sourceAtpvo == null) {
/* 136 */       return atpvos;
/*     */     }
/* 138 */     HashMap<String, UFDouble> bodyNumMap = ATPBillManage.getInstance().getDifferencesNum(cbilltype, bidAndDimmap, billparams[0]);
/* 139 */     Map<String, CircularlyAccessibleValueObject> map = new HashMap<String, CircularlyAccessibleValueObject>();
/* 140 */     ATPBill atpbill = ATPBillManage.getInstance().getATPBill(cbilltype);
/* 141 */     for (int i = 0; i < billparams.length; i++) {
/* 142 */       CircularlyAccessibleValueObject[] childs = billparams[i].getChildrenVO();
/* 143 */       for (int j = 0; j < childs.length; j++) {
/* 144 */         String sourcebid = childs[j].getAttributeValue(atpbill.getSourceBidKey()) + "";
/* 145 */         map.put(sourcebid, childs[j]);
/*     */       } 
/*     */     } 
/* 148 */     for (int i = 0; i < sourceAtpvo.length; i++) {
/* 149 */       String key = AtpVOUtil.getAtpKey(sourceAtpvo[i]);
/* 150 */       String bid = bidAndDimmap.get(key) + "";
/* 151 */       CircularlyAccessibleValueObject bodyvo = (CircularlyAccessibleValueObject)map.get(bid);
/* 152 */       if (bodyvo != null) {
/*     */         
/* 154 */         UFDouble diffenancennum = (bodyNumMap.get(bodyvo.getPrimaryKey()) == null) ? new UFDouble(0) : (UFDouble)bodyNumMap.get(bodyvo.getPrimaryKey());
/* 155 */         String sourceBillTypeId = bodyvo.getAttributeValue(atpbill.getSourceBillTypeKey()) + "";
/* 156 */         String srctypeCode = infoQuery.getBilltypecodeByPk(sourceBillTypeId);
/* 157 */         ATPBill sourceAtpbill = ATPBillManage.getInstance().getATPBill(srctypeCode);
/* 158 */         UFDouble num = ((UFDouble)sourceAtpvo[i].getAttributeValue(sourceAtpbill.getAtpVoKey())).sub(diffenancennum);
/* 159 */         sourceAtpvo[i].setAttributeValue(sourceAtpbill.getAtpVoKey(), (num.doubleValue() < 0.0D) ? new UFDouble(0) : num);
/*     */       } 
/*     */     } 
/* 162 */     return (AtpVO[])CollectionUtils.combineArrs(new AtpVO[][] { atpvos, sourceAtpvo });
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void chenkAtp(String cbilltype, AggregatedValueObject[] bills) throws BusinessException {
/* 169 */     int status = bills[0].getParentVO().getStatus();
/* 170 */     AtpVO[] beforeAtpVOs = null;
/* 171 */     AtpVO[] aftervos = null;
/* 172 */     if (status == 3) {
/* 173 */       beforeAtpVOs = ATPBillManage.getInstance().getAllATPVOs(cbilltype, bills, false);
/*     */     } else {
/* 175 */       beforeAtpVOs = null;
/* 176 */       aftervos = ATPBillManage.getInstance().getATPBill(cbilltype).getAtpVoByTemp(bills);
/*     */     } 
/*     */     
AtpVO[] updatevos =
VOEntityUtil.mergeDiffNumVOs(CollectionUtils.combineArrs(
    AtpVO.atpDims, new String[] {
      AtpVO.PK_BATCHCODE
    }), AtpVO.atpNums, aftervos, beforeAtpVOs);/* /*     */ 
/*     */ 
/*     */     
/* 183 */     ((IATPService)NCLocator.getInstance().lookup(IATPService.class)).checkAtp(updatevos);
/*     */   }
/*     */ }


/* Location:              E:\zhuhai_ncc\NCC2111\modules\ic\META-INF\lib\ic_atp_share.jar!/nc/pubimpl/ic/atp/service/ATPUpdateImpl.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */